package com.database.bean;

import javax.persistence.AttributeOverride;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.xml.bind.annotation.XmlRootElement;

import sim.engine.SimState;
import sim.engine.Steppable;

import com.simulation.AgentsSimulation;
import com.simulation.SimulationStrategyMain;

@Entity
@Table(name="AGENT")
@AttributeOverride( name="id", column = @Column(name="id") )
@XmlRootElement
public class Agent extends BaseBean implements Steppable{

	private static final long serialVersionUID = 1L;
	
	@Min(0)
	@Max(1)
	@Column(name="preferenceQuality")
	private Double preferenceQuality;
	
	@Min(0)
	@Max(1)
	@Column(name="preferencePrice")
	private Double preferencePrice;
	
	@Min(0)
	@Max(1)
	@Column(name="preferenceImage")
	private Double preferenceImage;
	
	@ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name="agenttype_id")
	private AgentType agentType=null;
	
	@ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name="companyproduct_id")
	private CompanyProduct companyProduct=null;

	@Transient
	private String agentName=null;
	
	/*
	 * Lets make an agent constructor method. "this" refers to the agent itself
	 */

	public Agent() {}
	
	public Agent(String agentName){
		this.agentName=agentName;
	}

	public String getAgentName() {
		return agentName;
	}

	public void setAgentName(String agentName) {
		this.agentName = agentName;
	}

	public void step(SimState state) {
		AgentsSimulation as = (AgentsSimulation) state;
		SimulationStrategyMain strategy=new SimulationStrategyMain();
		strategy.performStrategy(as,this);
	} // end step method


	public Double getPreferenceQuality() {
		return preferenceQuality;
	}

	public void setPreferenceQuality(Double preferenceQuality) {
		this.preferenceQuality = preferenceQuality;
	}

	public Double getPreferencePrice() {
		return preferencePrice;
	}

	public void setPreferencePrice(Double preferencePrice) {
		this.preferencePrice = preferencePrice;
	}

	public Double getPreferenceImage() {
		return preferenceImage;
	}

	public void setPreferenceImage(Double preferenceImage) {
		this.preferenceImage = preferenceImage;
	}

	public AgentType getAgentType() {
		return agentType;
	}

	public void setAgentType(AgentType agentType) {
		this.agentType = agentType;
	}

	public CompanyProduct getCompanyProduct() {
		return companyProduct;
	}

	public void setCompanyProduct(CompanyProduct companyProduct) {
		this.companyProduct = companyProduct;
	}
	
	
} // end of Agent class
